package com.jz.yanshe.ui;

import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;

import com.alipay.sdk.app.PayTask;
import com.jz.jd.rest.business.RestProxy;
import com.jz.jd.rest.response.BaseResponse;

import jz.com.feierman.R;
import com.jz.yanshe.base.BaseActivity;
import com.jz.yanshe.util.PreferencesHelper;

import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by liuwei on 2018/5/7.
 */

public class AlipayActivity extends BaseActivity implements View.OnClickListener{


    private Button btn_pay;
    private CheckBox checkbox_alipay;


    @Override
    protected void initViews() {
        btn_pay=findViewById(R.id.btn_pay);
        checkbox_alipay=findViewById(R.id.checkbox_alipay);

    }

    @Override
    protected void initData() {

        btn_pay.setOnClickListener(this);
    }



    @Override
    protected int getLayoutResource() {
        return R.layout.activity_alipay;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_pay:
                if (checkbox_alipay.isChecked()){
                    RestProxy.getInstance().aliply(PreferencesHelper.getInstance().getString(this, "token"),"549", new Observer<BaseResponse>(){

                        @Override
                        public void onSubscribe(Disposable d) {
                        }

                        @Override
                        public void onNext(BaseResponse baseResponse) {
                            if (baseResponse.data instanceof String){
                                String orderInfo  = (String) baseResponse.data;
                                PayTask alipay = new PayTask(AlipayActivity.this);
                                Map<String, String> result = alipay.payV2(orderInfo,true);
                            }
                        }

                        @Override
                        public void onError(Throwable e) {

                        }

                        @Override
                        public void onComplete() {

                        }
                    } );



                }else {
                    Toast.makeText(this,"请选择支付方式",Toast.LENGTH_SHORT).show();
                }
                break;
        }

    }
}
